<template>
  <el-dialog
      :model-value="dialogVisible"
      :title="props.dialogCerEviTitle"
      width="40%"
      @close="handleClose"
  >
    <el-form :model="form" ref="formRef"  label-width="auto" size="large" :rules="rules">
      <el-form-item v-for="(item, index) in optionInfo"
                    :key="index"
                    label-position="top"
                    :label="item.label"
                    :prop="item.prop">
          <my-upload
              :file-type="'qyInfo'"
              @get-form-pic-value="getFormPicValue"
              :attribute="item.prop"
          >
          </my-upload>
      </el-form-item>
    </el-form>
    <template #footer>
      <span>
        <el-button @click="handleClose">取消</el-button>
        <el-button type="primary" @click="handleConfirm">
          确认
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import {defineEmits, ref, defineProps, onMounted} from 'vue'
import MyUpload from "@/components/commons/myUpload.vue";

const props = defineProps({
  dialogCerEviTitle: {
    type: String,
    default: '',
    required: true
  },
  dialogCerEviTableValue: {
    type: Object,
    default: {}
  },
  queryForm: {
  },
  dialogVisible: {
    type: Boolean,
    default: false
  },
  optionInfo: {
    type: Object,
    default: {}
  },
})

const formRef = ref(null)
const form = ref({
  qydm: '',
  qymc: '',
  fzr: '',
  fzrtel: '',
  xydm: '',
  addr: '',
  zyyw: '',
  zycp: '',
  jygm: '',
  dwjj: '',
  businessLicense: '',
  cardX: '',
  cardY: '',
  qtpic: '',
})
onMounted(async ()=> {
  form.value = props.dialogCerEviTableValue
  console.log(form.value)
})

const rules = ref({
  businessLicense: [{
    required: true,
    message: '不能为空',
    trigger: ['blur', 'change'],
  }],
  cardX: [{
    required: true,
    message: '不能为空',
    trigger: ['blur', 'change'],
  }],
  cardY: [{
    required: true,
    message: '不能为空',
    trigger: ['blur', 'change'],
  }],
})
const getFormPicValue = (value)=> {
  console.log(value)
  if (value.attr === 'businessLicense') {
    form.value.businessLicense = value.pic
  } else if (value.attr === 'cardX') {
    form.value.cardX = value.pic
  } else if (value.attr === 'cardY') {
    form.value.cardY = value.pic
  } else if (value.attr === 'qtpic') {
    form.value.qtpic = value.pic
  }
}
const emits = defineEmits(['update:modelValue', 'handleConfirm'])
const handleClose = ()=> {
  emits('update:modelValue', false)
}
const handleConfirm = () => {
  emits("handleConfirm", {...form.value}, {...formRef.value})
}

</script>

<style scoped>


</style>